//-----------------------------------------------------------------------------------
//
// Bitfighter - A multiplayer vector graphics space game
// Based on Zap demo released for Torque Network Library by GarageGames.com
//
// Derivative work copyright (C) 2008-2009 Chris Eykamp
// Original work copyright (C) 2004 GarageGames.com, Inc.
// Other code copyright as noted
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful (and fun!),
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//------------------------------------------------------------------------------------

#ifndef STRING_UTILS_H
#define STRING_UTILS_H

#ifdef _MSC_VER
#pragma warning (disable: 4996)     // Disable POSIX deprecation, certain security warnings that seem to be specific to VC++
#endif

#include "tnlVector.h"     // For Vector
#include "tnlTypes.h"
#include <string>

using namespace std;
using namespace TNL;

namespace Zap
{


// From http://stackoverflow.com/questions/134569/c-exception-throwing-stdstring
struct SaveException : public std::exception
{
   string msg;

   SaveException(string str) : msg(str) { /* do nothing */ }    // Constructor
   ~SaveException() throw() { /* do nothing */ }                // Destructor, needed to avoid "looser throw specifier" errors with gcc
   const char* what() const throw() { return msg.c_str(); }
};


// Collection of useful string things

string ExtractDirectory(const std::string& path);

string ExtractFilename(const std::string& path);

string itos(S32 i);
string itos(U32 i);
string itos(U64 i);
string itos(S64 i);
string ftos(float f, int digits);


string replaceString(const string &strString, const string &strOld, const string &strNew);

string listToString(Vector<string> &words, char seperator);

// TODO: Merge these methods
TNL::Vector<string> parseString(const string &line);
void parseString(const char *inputString, TNL::Vector<string> &words, char seperator);

string concatenate(const TNL::Vector<string> &words, TNL::S32 startingWith = 0);

string lcase(string strToConvert);
string ucase(string strToConvert);


void s_fprintf(FILE *stream, const char *format, ...);      // throws SaveException

//bool caseInsensitiveStringCompare(const string &str1, const string &str2);

// File utils
bool fileExists(const string &path);               // Does file exist?
bool makeSureFolderExists(const string &dir);      // Like the man said: Make sure folder exists
bool getFilesFromFolder(const string& dir, Vector<string>& files, const string& extension = "");


// Two different variations on joining file and folder names
string strictjoindir(const string &part1, const string &part2);
string strictjoindir(const string &part1, const string &part2, const string &part3);

string trim_right(const string &source, const string &t = " ");
string trim_left(const string &source, const string &t = " ");
string trim(const string &source, const string &t = " ");

S32 countCharInString(const string &source, char search);

string makeFilenameFromString(const char *levelname);

};

#endif
